import { createServer } from 'http';
import { remove } from 'lodash';
import { Server, Socket } from 'socket.io';

const httpServer = createServer();
const io = new Server(httpServer, {
    cors: {
        origin: '*',
    },
});
const config: modeConfig = {
    type: 'online',
    mode: 'identity',
    cardPile: 'junzheng',
    playerNum: 3,
    eHubs: [],
};
io.on('connection', (socket: Socket) => {
    console.log(`${socket.id}已连接...`);
    socket.on('setSocketId', id => {
        socket.data.socketId = id;
        (config.eHubs as Socket[]).push(socket);
    });
    socket.on('disconnect', () => {
        console.log(`${socket.id}已断开...`);
        remove(config.eHubs as Socket[], i => i.data.socketId === socket.data.socketId);
    });
});

httpServer.listen(5555);
console.clear();
console.log('成功启动服务器...');
